<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>设置表样式</title>
  <script src="./js/jexcel.js"></script>
  <script src="./js/jsuites.js"></script>
  <link rel="stylesheet" href="./css/jsuites.css" type="text/css" />
  <link rel="stylesheet" href="./css/jexcel.css" type="text/css" />
</head>

<body>
  <h1>设置表样式</h1>
  <h3>如何将样式应用到你的表格中</h3>

  <p>1：您可以在初始化期间为特定的列定义CSS，或者通过编程的javascript调用。
    但是，在初始化之后，仍然可以使用getStyle或setStyle方法以编程方式管理单元格样式。</p>
  <div id="spreadsheet"></div>

  <div>
    <button type="button" onclick="table.setStyle('A2', 'background-color', 'yellow');">设置A2背景</button>
    <button type="button"
      onclick="table.setStyle({ A3:'font-weight: bold; color:red;', B3:'background-color: yellow;', C3:'text-decoration: underline;', A4:'text-align:left;' });">改变A3,
      B3, C3, A4样式</button>
    <button type="button" onclick="document.getElementById('console').innerHTML = table.getStyle('A1');">获取A1样式</button>
    <button type="button"
      onclick="document.getElementById('console').innerHTML = JSON.stringify(table.getStyle());">获取表格样式</button>
  </div>

  <p>
    <textarea id='console' style='width:100%;max-width:600px;height:100px;'></textarea>
  </p>
</body>

<script>
  var data1 = [
    ['US', 'Cheese', 'Yes', '2019-02-12'],
    ['CA;US;UK', 'Apples', 'Yes', '2019-03-01'],
    ['CA;BR', 'Carrots', 'No', '2018-11-10'],
    ['BR', 'Oranges', 'Yes', '2019-01-12'],
  ];
  var table = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data1,
    columns: [
      {
        type: 'dropdown',
        title: 'Product Origin',
        width: 300,
        url: './static/countries.json', // Remote source for your dropdown
        autocomplete: true,
        multiple: true
      },
      {
        type: 'text',
        title: 'Description',
        width: 200
      },
      {
        type: 'dropdown',
        title: 'Stock',
        width: 100,
        source: ['No', 'Yes']
      },
      {
        type: 'calendar',
        title: 'Best before',
        width: 100
      },
    ],
    style: {
      A1: 'background-color: orange;',
      B1: 'background-color: orange;',
    },
  });
</script>

</html>